package com.boolib.animate.framework.web;


import com.boolib.animate.commons.Consts;
import com.boolib.animate.commons.base.BaseController;
import com.boolib.animate.framework.entity.AnimateChapter;

import com.boolib.animate.framework.service.advice.AnimateChapterService;
import com.boolib.animate.framework.service.base.impl.BaseAnimateChapterService;
import com.github.pagehelper.PageInfo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * @author nier
 * @create 2020-02-20 18:37
 */

@RequestMapping("/api/chapter")
@RestController
public class AnimateChapterController  {

    @Autowired
    private BaseAnimateChapterService baseAnimateChapterService;


    @GetMapping
    public List<AnimateChapter> queryChapterList(@RequestParam("workId") Long workId,@RequestParam(value = "sort",defaultValue = "asc")String sort){

        Example example = new Example(AnimateChapter.class);
        example.createCriteria().andEqualTo("workId",workId).andEqualTo("isDel", Consts.ENABLE).andEqualTo("showStatus",Consts.ENABLE);
        if("desc".equals(sort)){
            example.orderBy("idxOrder").desc();
        }
        else{
            example.orderBy("idxOrder").asc();
        }
        return baseAnimateChapterService.queryByExample(example);

    }



}
